package com.tesis_2.UI;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.ArrayList;

import org.json.JSONException;

import com.example.t2_clientback.R;
import com.example.t2_clientback.R.layout;
import com.example.t2_clientback.R.menu;
import com.tesis_2.BL.BLLocales;
import com.tesis_2.BL.BLReservas;
import com.tesis_2.BL.BLRestaurants;
import com.tesis_2.MO.MOLocal;
import com.tesis_2.MO.MOReserva;
import com.tesis_2.MO.MORestaurant;
import com.tesis_2.Utils.UTLocalesSimpleAdapter;
import com.tesis_2.Utils.UTReservaSimpleAdapter;

import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;

public class UIAceptarReserva extends ListActivity {
	
	private Integer nRest;
	private Integer nLocal;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_uiaceptar_reserva);
		Bundle b = getIntent().getExtras();
		nRest = b.getInt("RestId");
		nLocal = b.getInt("LocalId");
		
		ArrayList<MOReserva> lsReserva = new ArrayList<MOReserva>();
		
		try {
			lsReserva =BLReservas.getReservasByRestLocal(nRest, nLocal);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		setListAdapter( new UTReservaSimpleAdapter(this, lsReserva));
		
		
	}
		
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_uiaceptar_reserva, menu);
		return true;
	}
	
	@Override 
    public void onListItemClick(ListView l, View v, int position, long id) {
		
		MOReserva rs = (MOReserva) getListAdapter().getItem(position);
		try {
			BLReservas.updateReservaStatus(rs.getId());
			finish();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
    }

}
